﻿using System;
using System.Data;
using System.Windows.Forms;

namespace idataplatform
{
    public partial class baseinfo2 : Form
    {
        public baseinfo2()
        {
            InitializeComponent();
        }

        private void baseinfo1_Load(object sender, EventArgs e)
        {
            conncls conn = new conncls();
            dataGridView1.DataSource = conn.Dts("SELECT ind,floor,brand,type,area,iname FROM baseinfo_ipark;");
        }

        private void 数据导出ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ExportExcel Et = new ExportExcel();
            Et.GridToExcel("招商蛇口佛山IPARK花园城商户基础数据", dataGridView1);
        }

        private void dataGridView1_DoubleClick(object sender, EventArgs e)
        {
            if (dataGridView1.CurrentRow != null)
            {
                basedetail1 form2 = new basedetail1(dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells[0].Value.ToString());
                form2.ShowDialog();
                if (form2.DialogResult == DialogResult.Cancel && pubcls.freshmark1 == true)
                {
                    conncls conn = new conncls();
                    dataGridView1.DataSource = conn.Dts("SELECT ind,floor,brand,type,area,iname FROM baseinfo_ipark;");
                    pubcls.freshmark1 = false;
                }
            }
        }

        private void 批量更新ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Title = "请选择文件夹";
            dialog.Filter = "excel07文件(*.xlsx)|*.xlsx|excel03文件(*.xls)|*.xls";
            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string file = dialog.FileName;

                ImportExcel ie = new ImportExcel();

                DataTable dt = new DataTable();
                dt = ie.ExcelToTable(file);

                if (dt.Columns.Count == 6 && dt.Columns[0].ColumnName == "编号")
                {
                    conncls conns = new conncls();
                    int i;
                    string upSql = "";
                    conns.sqlexec("TRUNCATE TABLE baseinfo_ipark;");
                    for (i = 0; i < dt.Rows.Count; i++)
                    {
                        upSql = upSql + "INSERT INTO baseinfo_ipark(iname,brand,type,area,floor) VALUES('" + dt.Rows[i][5].ToString() + "','" + dt.Rows[i][2].ToString() + "','" + dt.Rows[i][3].ToString() + "'," + dt.Rows[i][4].ToString() + ",'" + dt.Rows[i][1].ToString() + "');";
                    }
                    conns.sqlexec(upSql);
                    dataGridView1.DataSource = conns.Dts("SELECT ind,floor,brand,type,area,iname FROM baseinfo_ipark;");
                }
                else
                {
                    MessageBox.Show("选择的数据表不正确或格式不正确，请联系管理员。");
                }
            }
        }


    }
}
